---
title: LibreChat
description: Connect LibreChat to Anyquery
---

import { Steps } from '@astrojs/starlight/components';

<img src="/icons/librechat.svg" alt="LibreChat" width="96" />

LibreChat is an open-source chat application for different LLM models. Using Anyquery, you can connect LibreChat to your local and online applications (such as Spotify, GitHub, Discord, etc.) and interact with them using natural language.

## Prerequisites

Before you begin, ensure that you have the following:

- A working installation of Anyquery (`v0.4.0`). Follow the [installation guide](/docs/#installation) if you haven't installed it yet.
- A few integrations set up in Anyquery. Refer to each [integration guide](/integrations) for more information.
- LibreChat hosted somewhere.

## Connect LibreChat to Anyquery

To connect Anyquery to LibreChat, you can either use the HTTP api (recommended) or the model context protocol.

### Ensuring agents are enabled

For both protocols, you need to enable Agents. By default, they should be enabled, and available in the `Agents` section of the model selection screen. If not,
ensure your `librechat.yaml` configuration file looks like this:

```yaml
version: 1.2.1

interface:
  agents: true

endpoints:
  agents:
    recursionLimit: 25 # Can be increased if needed
    disableBuilder: false
    capabilities: ["actions", "tools"] # You can add other capabilities here
  ...
```

If you still cannot see the `Agents` section, check your environment variables. The `ENDPOINTS` variable should include `agents`.

```env
ENDPOINTS=azureOpenAI,gptPlugins,agents,openAI
```

### HTTP API

<Steps>

1. #### Start Anyquery

    In a terminal, run the following command to start Anyquery:

    ```bash title="Terminal"
    anyquery gpt
    ```

    This command will start a tunnel to Anyquery and provide you a bearer token. You must then use this token to authenticate your requests to Anyquery.

    ```txt title="Terminal" "Your Anyquery ID is ikabcjde"
    julien@MacBook-Air-Julien anyquery % anyquery gpt


    Your Anyquery ID is ikabcjde. This is your bearer token that you must set in chatgpt.com


    2025-02-10 21:29:12.293 [I] [client/service.go:295] try to connect to server...
    2025-02-10 21:29:12.453 [I] [client/service.go:287] [cc07e04c16c1e59f] login to server success, get run id [cc07e04c16c1e59f]
    2025-02-10 21:29:12.454 [I] [proxy/proxy_manager.go:173] [cc07e04c16c1e59f] proxy added: [ikabcjde]
    2025-02-10 21:29:12.494 [I] [client/control.go:168] [cc07e04c16c1e59f] [ikabcjde] start proxy success
    ```

2. #### Set up LibreChat

    Select the `Agents` section in the model selection screen, and create a new one.
    <img src="/images/docs/llm/librechat-agent-selection.png" alt="LibreChat Agents" width="360" />

    In the right panel, fill in the fields for your new agent.
    - **Name** and **Description**: Give your agent a name and a description.
    - **Instructions** Go to [this gist](https://gist.githubusercontent.com/julien040/75578d04c53a13bbc4ab223026b975d4/raw/0924e5d28388ab979cd4294f84770dc2cef87907/librechat-gpt-instructions.txt) and copy the content to the instructions field.
    - **Model**: Select the LLM model you want to use with LibreChat.

    Click on `Create` to save your agent.

    ![LibreChat Agent](/images/docs/llm/librechat-agent-creation.png)

    Now that your agent is created, click on `Add actions` to connect it to Anyquery.<br />
    Under authentication, select `API Key`, select `Bearer` as Auth Type, and paste the bearer token you received from Anyquery.
    ![LibreChat Auth](/images/docs/llm/librechat-auth.png)

    Then, go to [this gist](https://gist.githubusercontent.com/julien040/75578d04c53a13bbc4ab223026b975d4/raw/15d78870270ceaf49b190a1e6d65af37a40b7b3e/openapi.yaml) and copy the content to the Schema field.

    <br />
    Finally, click on `Create` to save your action. Go back, and then click on `Save` to save your agent.
    ![LibreChat End result](/images/docs/llm/librechat-http-result.png)

    <br />
    Congratulations 🎉. LibreChat is connected to Anyquery.

</Steps>

### Model Context Protocol

Anyquery can also connect to LibreChat using the Model Context Protocol (MCP). 

<Steps>

1. #### Set up LibreChat

    Open the `librechat.yaml` configuration file, and add the following configuration:

    ```yaml
    version: 1.2.1

    mcpServers:
        anyquery:
            command: anyquery
            args:
                - mcp

    # Rest of your configuration
    ```

    Now, we will create a new agent in LibreChat. Select the `Agents` section in the model selection screen, and create a new one.
    <img src="/images/docs/llm/librechat-agent-selection.png" alt="LibreChat Agents" width="360" />

    In the right panel, fill in the fields for your new agent.
    - **Name** and **Description**: Give your agent a name and a description.
    - **Instructions** You can leave it empty.
    - **Model**: Select the LLM model you want to use with LibreChat.

    Now, click on `Add Tools` to add Anyquery as a tool. Go to the last page, and add:
        - listTables
        - describeTable
        - executeQuery

    ![LibreChat Tools](/images/docs/llm/librechat-tool-selection.png)

    Finally, click on `Create` to save your agent. Go back, and then click on `Save` to save your agent.

</Steps>

### Selecting the agent

Now that you have set up your agent, go back to the `Agents` section in LibreChat, and select the agent you just created in the right panel
![LibreChat Agent Selection](/images/docs/llm/librechat-agent-right-panel.png)

You can now start interacting with LibreChat using natural language. Here are a few examples:
- **What can you do?**
- **Recommend me a song according to my history.**
- **Take this PDF, and open the references in my browser.**
- **Here is a link to my schedule, when should I schedule a meeting?**
